package org.hfy.exception;

/**
 * 仓库管理业务异常
 * 
 * @author hfy
 * @version 1.0
 */
public class WarehouseException extends BusinessException {

    public WarehouseException(String message) {
        super(message);
    }

    public WarehouseException(int code, String message) {
        super(code, message);
    }

    /**
     * 库存不足异常
     */
    public static class InsufficientStockException extends WarehouseException {
        public InsufficientStockException(String factoryNo, Integer currentStock, Integer requestQuantity) {
            super(4001, String.format("库存不足 - 厂内编号：%s，当前库存：%d，申请出库：%d", 
                factoryNo, currentStock, requestQuantity));
        }
    }

    /**
     * 数据不存在异常
     */
    public static class DataNotFoundException extends WarehouseException {
        public DataNotFoundException(String dataType, Object id) {
            super(4004, String.format("%s不存在，ID：%s", dataType, id));
        }
    }

    /**
     * 业务状态异常
     */
    public static class InvalidStatusException extends WarehouseException {
        public InvalidStatusException(String operation, String currentStatus, String requiredStatus) {
            super(4002, String.format("无法执行%s操作，当前状态：%s，要求状态：%s", 
                operation, currentStatus, requiredStatus));
        }
    }

    /**
     * 数量验证异常
     */
    public static class QuantityValidationException extends WarehouseException {
        public QuantityValidationException(String message) {
            super(4003, message);
        }
    }

    /**
     * 单号生成异常
     */
    public static class NumberGenerationException extends WarehouseException {
        public NumberGenerationException(String numberType, Throwable cause) {
            super(5001, String.format("%s生成失败: %s", numberType, cause.getMessage()));
        }
    }

    /**
     * 并发操作异常
     */
    public static class ConcurrentOperationException extends WarehouseException {
        public ConcurrentOperationException(String operation) {
            super(4009, String.format("并发操作冲突：%s，请稍后重试", operation));
        }
    }
}